import 'package:eyepetizer_example/config/string.dart';
import 'package:eyepetizer_example/page/discovery/follow_page.dart';
import 'package:eyepetizer_example/widget/app_bar.dart';
import 'package:flutter/material.dart';

import '../widget/tab_bar.dart';
import 'discovery/category_page.dart';
import 'discovery/news_page.dart';
import 'discovery/recommend_page.dart';
import 'discovery/topic_page.dart';

const TAB_LABEL = ['关注', '分类', '专题', '资讯', '推荐'];
class DiscoveryPage extends StatefulWidget {
  const DiscoveryPage({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _DiscoveryPageState();

}

class _DiscoveryPageState extends State<StatefulWidget> with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin{
  late TabController _tabController;
  @override
  void initState() {
    super.initState();
    // vsync:ticker 驱动动画,每次屏幕刷新都会调用TickerCallback，
    _tabController = TabController(length: TAB_LABEL.length, vsync: this);
  }
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: appBar(
        AppString.discovery,
          showBack: false,
        bottom: tabBar(
          controller: _tabController,
          tabs: TAB_LABEL.map((String label){
            return Tab(text: label,);
          }).toList()
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: const [
          FollowPage(),
          CategoryPage(),
          TopicPage(),
          NewsPage(),
          RecommendPage(),
        ],
      )
    );
  }

  @override
  bool get wantKeepAlive => true;

}

